package com.etheart.model.entity;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.etheart.model.enums.EnableState;

/**
 * User entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "_user", catalog = "etheart")
public class User implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Long id;
	private Role role;
	private String username;
	private String password;
	private String salt;
	private EnableState disabled;
	private Date registerTime;
	private String email;
	private String facePath;
	private Set<Role> roles = new HashSet<Role>(0);
	private Set<Report> reports = new HashSet<Report>(0);

	// Constructors

	/** default constructor */
	public User() {
	}

	/** minimal constructor */
	public User(String username) {
		this.username = username;
	}

	/** full constructor */
	public User(Role role, String username, String password, String salt,
			EnableState disabled, Date registerTime, String email,
			String facePath, Set<Role> roles, Set<Report> reports) {
		this.role = role;
		this.username = username;
		this.password = password;
		this.salt = salt;
		this.disabled = disabled;
		this.registerTime = registerTime;
		this.email = email;
		this.facePath = facePath;
		this.roles = roles;
		this.reports = reports;
	}

	// Property accessors
	@Id
	@GeneratedValue
	@Column(name = "id", unique = true, nullable = false)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "roleid")
	public Role getRole() {
		return this.role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@Column(name = "username",  unique = true, nullable = false, length = 20)
	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Column(name = "password", length = 32)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "salt", length = 20)
	public String getSalt() {
		return this.salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}

	@Column(name = "disabled",length=10)
	@Enumerated(EnumType.STRING)
	public EnableState getDisabled() {
		return this.disabled;
	}

	public void setDisabled(EnableState disabled) {
		this.disabled = disabled;
	}

	@Column(name = "register_time", length = 19)
	public Date getRegisterTime() {
		return this.registerTime;
	}

	public void setRegisterTime(Date registerTime) {
		this.registerTime = registerTime;
	}

	@Column(name = "email", length = 100)
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "face_path")
	public String getFacePath() {
		return this.facePath;
	}

	public void setFacePath(String facePath) {
		this.facePath = facePath;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "_role_user", catalog = "etheart", joinColumns = { @JoinColumn(name = "userid", updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "roleid", updatable = false) })
	public Set<Role> getRoles() {
		return this.roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user")
	public Set<Report> getReports() {
		return this.reports;
	}

	public void setReports(Set<Report> reports) {
		this.reports = reports;
	}

}